unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ActnList, ComCtrls, Menus, ToolWin, ImgList, ExtActns, StdActns,
  StdCtrls;

type
  TForm1 = class(TForm)
    ActionList1: TActionList;
    FileNew: TAction;
    ToolBar1: TToolBar;
    MainMenu1: TMainMenu;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    N1: TMenuItem;
    N2: TMenuItem;
    ImageList1: TImageList;
    Open1: TMenuItem;
    Run1: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    HelpAction: TAction;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    EditCut: TEditCut;
    EditCopy: TEditCopy;
    EditPaste: TEditPaste;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    ToolButton8: TToolButton;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    WindowCascade1: TWindowCascade;
    WindowTileHorizontal1: TWindowTileHorizontal;
    WindowTileVertical1: TWindowTileVertical;
    N12: TMenuItem;
    RichEditAlignLeft1: TRichEditAlignLeft;
    RichEditAlignRight1: TRichEditAlignRight;
    RichEditAlignCenter1: TRichEditAlignCenter;
    N13: TMenuItem;
    N14: TMenuItem;
    N15: TMenuItem;
    N16: TMenuItem;
    RichEditBold1: TRichEditBold;
    RichEditItalic1: TRichEditItalic;
    RichEditUnderline1: TRichEditUnderline;
    RichEditStrikeOut1: TRichEditStrikeOut;
    RichEditBullets1: TRichEditBullets;
    N17: TMenuItem;
    N18: TMenuItem;
    N19: TMenuItem;
    N20: TMenuItem;
    N21: TMenuItem;
    N22: TMenuItem;
    EditUndo1: TEditUndo;
    ToolButton19: TToolButton;
    N23: TMenuItem;
    SaveDialog1: TSaveDialog;
    PrintDialog1: TPrintDialog;
    PageSetupDialog1: TPageSetupDialog;
    ToolBar2: TToolBar;
    ToolButton20: TToolButton;
    ToolButton21: TToolButton;
    ToolButton22: TToolButton;
    ToolButton23: TToolButton;
    ToolButton24: TToolButton;
    ToolButton25: TToolButton;
    ToolButton26: TToolButton;
    ToolButton27: TToolButton;
    ToolButton28: TToolButton;
    ComboBox2: TComboBox;
    FontDialog1: TFontDialog;
    ColorDialog1: TColorDialog;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    Color: TAction;
    Font: TAction;
    ToolButton11: TToolButton;
    Print: TAction;
    N24: TMenuItem;
    PopupMenu1: TPopupMenu;
    Save: TAction;
    OpenDialog1: TOpenDialog;
    Open: TAction;
    PageSetup: TAction;
    N25: TMenuItem;
    N26: TMenuItem;
    EditSelectAll1: TEditSelectAll;
    N27: TMenuItem;
    N28: TMenuItem;
    N29: TMenuItem;
    SelectAll1: TMenuItem;
    StatusBar1: TStatusBar;
    procedure FileNewExecute(Sender: TObject);
    procedure HelpActionExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure ColorExecute(Sender: TObject);
    procedure FontExecute(Sender: TObject);
    procedure PrintExecute(Sender: TObject);
    procedure SaveExecute(Sender: TObject);
    procedure OpenExecute(Sender: TObject);
    procedure PageSetupExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses
 ChildUnit, HelpUnit;
{$R *.dfm}

procedure TForm1.HelpActionExecute(Sender: TObject);
var
HelpForm:THelpForm;
begin
 try
 HelpForm:=THelpForm.Create(Self);
 HelpForm.ShowModal;
 finally
HelpForm.free;
end;
end;


procedure TForm1.OpenExecute(Sender: TObject);
begin


 if OpenDialog1.Execute then
    begin
    FileNewExecute(Self);

    if MDIChildCount>0 then

  (ActiveMDIChild as TChildForm).richedit.Lines.LoadFromFile(OpenDialog1.FileName);
end;
 end;
procedure TForm1.SaveExecute(Sender: TObject);
begin
 if SaveDialog1.Execute and (MDIChildCount>0) then
 begin
   if SaveDialog1.FilterIndex=1 then (ActiveMDIChild as TChildForm).richedit.PlainText:=true else (ActiveMDIChild as TChildForm).richedit.PlainText:=false;

    if MDIChildCount>0 then
 (ActiveMDIChild as TChildForm).richedit.Lines.SaveToFile(SaveDialog1.FileName);
end;
end;
procedure TForm1.ToolButton10Click(Sender: TObject);
begin
 if MDIChildCount>0 then
 (ActiveMDIChild as TChildForm).richedit.SelAttributes.Color:=ColorDialog1.Color;
end;

procedure TForm1.PageSetupExecute(Sender: TObject);
begin
   if MDIChildCount>0 then
   PageSetupDialog1.Execute

end;

procedure TForm1.PrintExecute(Sender: TObject);
begin
 if PrintDialog1.Execute and (MDIChildCount>0) then
(ActiveMDIChild as TChildForm).richedit.Print('123');
end;

procedure TForm1.ColorExecute(Sender: TObject);
begin
if ColorDialog1.Execute and (MDIChildCount>0) then
(ActiveMDIChild as TChildForm).richedit.SelAttributes.Color:=ColorDialog1.Color;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
begin
 if MDIChildCount>0 then
(ActiveMDIChild as TChildForm).richedit.SelAttributes.Name:=Combobox2.text;
end;

procedure TForm1.FileNewExecute(Sender: TObject);

begin
     TChildForm.Create(Self);

end;

procedure TForm1.FontExecute(Sender: TObject);
begin
if FontDialog1.Execute and (MDIChildCount>0) then
(ActiveMDIChild as TChildForm).richedit.Font:=FontDialog1.Font;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox2.Items:=Screen.Fonts;
end;

end.
